package com.xiaoc.bulldozer.springboot.config.web;//package com.xiaoc.bulldozer.springboot.config.web;
//
//import java.io.IOException;
//
//import javax.servlet.Filter;
//import javax.servlet.FilterChain;
//import javax.servlet.FilterConfig;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.apache.commons.lang3.StringUtils;
//import org.springframework.stereotype.Component;
//
///**
// * Created by hadoop on 2017.11.09.
// */
//@Component
//public class CorsFilter implements Filter {
//
//    @Override
//    public void init(FilterConfig filterConfig) throws ServletException {
//
//    }
//
//    @Override
//    public void doFilter(ServletRequest request, ServletResponse response, FilterChain filterChain) throws IOException, ServletException {
//
//        HttpServletResponse httpResponse = (HttpServletResponse) response;
//        HttpServletRequest httpRequest = (HttpServletRequest) request;
//
//        if (StringUtils.equals(httpRequest.getMethod(), "OPTIONS")) {
//            httpResponse.addHeader("Access-Control-Allow-Origin", httpRequest.getHeader("Origin"));
//            httpResponse.addHeader("Access-Control-Allow-Headers", httpRequest.getHeader("Access-Control-Request-Headers"));
//            httpResponse.addHeader("Access-Control-Allow-Credentials", "true");
//            httpResponse.addHeader("Access-Control-Allow-Methods", "GET,HEAD,POST");
//        }
//
//        filterChain.doFilter(httpRequest, httpResponse);
//    }
//
//    @Override
//    public void destroy() {
//
//    }
//}
